<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ page import="java.sql.*,bean.*,vo.*,dao.*,java.util.ArrayList" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>分页浏览记录</title>
</head>
<body bgcolor="aaaaff">
 <center>
  分页显示记录内容
  <hr>
  <table border="1" bgcolor="cccfff" align="center">
   <tr>
    <td>编号</td>
    <td>姓名</td>
    <td>性别</td>
    <td>职称</td>     
   </tr> 
   <jsp:useBean id="tdao" class="dao.TeacherDao"></jsp:useBean>
 <jsp:useBean id="tea" class="vo.Teacher"></jsp:useBean>  
  <%
    //Connection con=DBConnectionManager.getConnection();
    ArrayList teas=tdao.getAllTeachers();
    int intPageSize;   //一页显示的记录数
    int intRowCount;   //记录总数
    int intPageCount;  //总页数
    int intPage;       //待显示页码
    String strPage;    
    int i;
    intPageSize=6;     //设置一页显示的记录数
    //取得待显示页码
    strPage=request.getParameter("page");
    if(strPage==null){
    	intPage=1;
    }
    else{
    	//将字符串转换成整形
    	intPage=java.lang.Integer.parseInt(strPage);
    	if(intPage<1)
    		intPage=1;
    }
   //rs.last();
   //获取记录总数
   intRowCount=teas.size();
   //计算总页数
   intPageCount=(intRowCount+intPageSize-1)/intPageSize;
   if(intPage>intPageCount)
	   //调整待显示的页码
	   intPage=intPageCount;
   if(intPageCount>0){
	   //显示数据
	   i=(intPage-1)*intPageSize+1-1;
	   while(i<intPageSize*intPage&&i<teas.size()){
	   	tea=(Teacher)teas.get(i);
	%>
	<tr>
	  <td><%=tea.getTeano() %></td>
	  <td><%=tea.getTeaname() %></td>
	  <td><%=tea.getTeasex()%></td>
	  <td><%=tea.getTitle() %></td>
	  
	</tr>
	<%
	//rs.next();
	i++;
	   }  
   }
   %>  
  </table>
  <hr>
  <div align="center">
         第<%=intPage %>页  共<%=intPageCount %>页
     <% if(intPage>1){
    %>
    <a href="lookTeacher.jsp?page=<%=1 %>">第一页</a>
    <a href="lookTeacher.jsp?page=<%=intPage-1 %>">上一页</a>
    
    <%
    }
     if(intPage<intPageCount){
    %>
    
    <a href="lookTeacher.jsp?page=<%=intPage+1 %>">下一页</a>
    <a href="lookTeacher.jsp?page=<%=intPageCount %>">最后一页</a>
    <%
     }
    %>
  </div>
 </center>
</body>
</html>